package com.zhilianbao.leyaogo.utils;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.request.target.GlideDrawableImageViewTarget;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.app.LeYaoGoApplication;

import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * ClassName: ImageUtils <br>
 * Description: 图片工具类<br>
 * Author: Cyarie <br>
 * Created: 2016/5/17 17:31 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class ImageUtils {

    //
    //    /**
    //     * 加载大头像
    //     *
    //     * @param url
    //     * @param imageView
    //     */
    //    public static void loadBigAvatar(String url, ImageView imageView) {
    //        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext()), new CropCircleTransformation(LeYaoGoApplication.getContext())).crossFade().placeholder(com.bql.robotmanager.R.drawable.logo_default_home).error(com.bql.robotmanager.R.drawable.logo_default_home).into(imageView);
    //    }
    //
    //

    /**
     * 加载小头像
     *
     * @param url
     * @param imageView
     */
    public static void loadSmallAvatar(String url, ImageView imageView) {
        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext()), new CropCircleTransformation(LeYaoGoApplication.getContext())).crossFade().placeholder(R.drawable.img_head_portrait).error(R.drawable.img_head_portrait).into(imageView);
    }

    //
    //    /**
    //     * 加载大图
    //     *
    //     * @param url
    //     * @param imageView
    //     */
    //    public static void loadLargeProduct(String url, ImageView imageView) {
    //        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext())).crossFade().placeholder(R.drawable.product_loding_big).error(R.drawable.product_loding_big).into(imageView);
    //    }
    //
    //
    //    /**
    //     * 加载大产品头像
    //     *
    //     * @param url
    //     * @param imageView
    //     */
    //    public static void loadBigProductAvatar(String url, ImageView imageView) {
    //        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext())).crossFade().placeholder(R.drawable.product_img_big).error(R.drawable.product_img_big).into(imageView);
    //    }
    //
    //
    //    /**
    //     * 加载大产品头像
    //     *
    //     * @param url
    //     * @param imageView
    //     */
    //    public static void loadBigProductAvatarWithRoundCorner(String url, ImageView imageView) {
    //        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext()), new RoundedCornersTransformation(LeYaoGoApplication.getContext(), 15, 0)).crossFade().placeholder(R.drawable.product_img_big).error(R.drawable.product_img_big).into(imageView);
    //    }
    //
    //    /**
    //     * 加载小产品头像
    //     *
    //     * @param url
    //     * @param imageView
    //     */
    //    public static void loadSmallProductAvatar(String url, ImageView imageView) {
    //        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext())).crossFade().placeholder(R.drawable.product_img_small).error(R.drawable.product_img_small).into(imageView);
    //    }
    //
    //
    //    /**
    //     * 加载本资源图片
    //     *
    //     * @param resId
    //     * @param imageView
    //     */
    //    public static void loadLargePicByRes(int resId, ImageView imageView) {
    //        Glide.with(LeYaoGoApplication.getContext()).load(resId).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext())).crossFade().placeholder(R.drawable.product_img_big).error(R.drawable.product_img_big).into(imageView);
    //    }


    /**
     * 加载首页Banner图片
     *
     * @param url
     * @param imageView
     */
    public static void loadHomeTopBanner(String url, ImageView imageView) {
        //        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext())).crossFade().placeholder(R.drawable.details_banner_img_default).error(R.drawable.details_banner_img_default).into(imageView);
        Glide.with(LeYaoGoApplication.getContext()).load(url).asBitmap().centerCrop().placeholder(R.drawable.home_banner_img_default).error(R.drawable.home_banner_img_default).into(imageView);

    }

    /**
     * 加载商品图片
     *
     * @param url
     * @param imageView
     */
    public static void loadGoodsPic(String url, ImageView imageView) {
        //        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext())).crossFade().placeholder(R.drawable.img_default_avatar).error(R.drawable.img_default_avatar).into(imageView);
        Glide.with(LeYaoGoApplication.getContext()).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).placeholder(R.drawable.goods_img_default).error(R.drawable.goods_img_default).into(imageView);
    }


    /**
     * 加载首页商品图片
     *
     * @param url
     * @param imageView
     */
    public static void loadHomeGoodsPic(String url, ImageView imageView) {
        //        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext())).crossFade().placeholder(R.drawable.img_default_avatar).error(R.drawable.img_default_avatar).into(imageView);
        Glide.with(LeYaoGoApplication.getContext()).load(url).asBitmap().placeholder(R.drawable.goods_img_default).error(R.drawable.goods_img_default).into(imageView);
    }

    /**
     * 加载热区图片
     *
     * @param url
     * @param imageView
     */
    public static void loadHotPic(String url, ImageView imageView) {
        Glide.with(LeYaoGoApplication.getContext()).load(url).crossFade().into(imageView);
    }

    /**
     * 加载首页栏目Pic
     *
     * @param url
     * @param imageView
     */
    public static void loadColumnPic(String url, ImageView imageView) {
        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext())).crossFade().placeholder(R.drawable.goods_img_default).error(R.drawable.goods_img_default).into(imageView);
    }

    /**
     * 加载首页栏目Pic
     *
     * @param url
     * @param imageView
     */
    public static void loadAdPic(String url, ImageView imageView) {
        Glide.with(LeYaoGoApplication.getContext()).load(url).bitmapTransform(new CenterCrop(LeYaoGoApplication.getContext())).crossFade().placeholder(R.color.color_FFFFFF).error(R.color.color_FFFFFF).into(imageView);
    }


    /**
     * 加载Splash Gif动画 指加载一次
     *
     * @param resId
     * @param imageView
     */
    public static void loadSplashGif(int resId, ImageView imageView) {
        Glide.with(LeYaoGoApplication.getContext()).load(resId).into(new GlideDrawableImageViewTarget(imageView, 1));
    }

    /**
     * 加载用户引导页
     *
     * @param resId
     * @param imageView
     */
    public static void loadUserGuidePic(int resId, ImageView imageView) {
        Glide.with(LeYaoGoApplication.getContext()).load(resId).into(imageView);
    }

    /**
     * 加载圆角矩形
     *
     * @param url
     * @param imageView
     */
    public static void loadRoundPic(String url, ImageView imageView) {
        Glide.with(LeYaoGoApplication.getContext()).load(url).diskCacheStrategy(DiskCacheStrategy.RESULT).placeholder(R.drawable.goods_img_default).error(R.drawable.goods_img_default).transform(new GlideRoundTransform(LeYaoGoApplication.getContext(), 4)).into(imageView);
    }

    /**
     * 加载轮播图和详情页面的大图
     *
     * @param url
     * @param imageView
     */
    public static void loadDetailPic(String url, ImageView imageView) {
        Glide.with(LeYaoGoApplication.getContext())
                .load(url)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)// 一定要加上这句话，防止出现第二次加载image太慢的问题
                .priority(Priority.IMMEDIATE)
                .dontAnimate()
                .placeholder(R.drawable.goods_img_default)
                .error(R.drawable.details_banner_img_default)
                .into(imageView);
    }
}







